package cn.itcast.springMVC.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

//请求控制器
@Controller
public class ParamController {
	
	//请求路径
	@RequestMapping("/pages/param")
	public String request(HttpServletRequest req) {
		
		String id = req.getParameter("id");
		
		System.out.println("id:"+id);
		
		return "success";	//默认为转发 ，重定向：redirect:../index.jsp
		
	}
	
	//model是用来给视图层传数据的
	@RequestMapping("/pages/model")
	public String model(Model model) {
		
		model.addAttribute("name", "王五");
		
		return "success";	//默认转发
	}
	
	@RequestMapping("/pages/session")
	public String session(HttpSession httpSession) {
		
		httpSession.setAttribute("name", "张三");
		
		return "success";	//默认转发
	}
	
	@RequestMapping("/pages/parameter")
	public String parametr(
			@RequestParam("title") String title1) {
		
		System.out.println(title1);
		
		return "success";
	}
	
	// /pages/parameter2?i=123&b=true&s=中&d=12.33&f=0.998&c=Z
	@RequestMapping("/pages/parameter2")
	public String parametr2(
			int i,
			boolean b,
			String s,
			Double d,
			float f,
			char c
			) {
		
		System.out.println("int"+i);
		
		System.out.println("boolean"+b);
		
		System.out.println("String"+s);
		
		System.out.println("Double"+d);
		
		System.out.println("float"+f);
		
		System.out.println("char"+c);
		
		return "success";
	}
	
	
}
